//求一个整数二进制位1的个数
import java.util.Scanner;
public class Num2 {
    public static int getCount(int num)
    {
        int count=0;
         if(num==0)
         {
             return 0;
         }
        System.out.print(num+"递归除2，二进制位为：");
         if((num%2)==1)
         {
             System.out.println("1 ");
             count++;
         }
         if((num%2)==0)
         {
             System.out.println("0 ");
         }
         return count+getCount(num/2);
    };
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int num=sc.nextInt();
        int count=getCount(num);
        System.out.print("\n"+num+"二进制里的1的个数："+count);

    }
}
